<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" type="text/css" href="{$Think.config.RESOURCEURL}wx_assets/css/product.css?v=201408281">
		<link rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/community/css/bootstrap.min.css{$Think.config.RESOURCE_VER}" />
		<link rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" onerror="_cdnFallback(this)">
		<if condition="$mallHue.mallHue eq '1'">
			<link rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/product/coupon_blue.css{$Think.config.RESOURCE_VER}" onerror="_cdnFallback(this)">
			<else/>
			<link rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/product/coupon.css{$Think.config.RESOURCE_VER}" onerror="_cdnFallback(this)">
		</if>
		<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
		<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/jquery.min.js{$Think.config.RESOURCE_VER}"></script>
		<script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
		<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}"></script>
		<title>我的优惠券</title>
	</head>
	<style>
		.coupon.active .media-left.select span
		{
			width: 23px;
			height: 23px;
			border-radius: initial;
			border: 0px;
			background: url({$Think.config.RESOURCEURL}wx_assets/images/product/couponselect.png);
			background-size:contain;
		}
	</style>
	
	<body>
	<script>
		$(function(){
			var type=$.util.getParamAsObject().type,
				oid=$.util.getParamAsObject().oid;
			var ids=$.util.getParamAsObject().ids;
			if(type!=0)
			{
				$('.disablebox').hide();
			}
			$('.tab-nav a').each(function(index){
				if(type==index)
				{
					$(this).addClass('active');
				}
				$(this).on('click',function(){
					window.location.href="call.html?customerId={$customerId}&module=product&method=couponList&params=%7B%22type%22:"+index+",%22oid%22:"+oid+",%22ids%22:"+ids+"}";
				})
			})
		})
	</script>
		<div class="top">
			<a href="javascript:history.go(-1);" class="back">
				<img src="{$Think.config.RESOURCEURL}wx_assets/images/product/arrow-left.png"/>
			</a>
			<div class="middle">
				优惠券
			</div>
		</div>
		<div class="tab-nav">
			<a >未使用({$canuserCount})</a>
			<a >已使用({$useredCount})</a>
			<a >已过期({$overdue})</a>
		</div>
			<div class="couponBox <if condition='$type eq 0'>selectList</if>">
				<if condition="$type eq 0">
				<volist name="couponList" id="s">
					
					<if condition="$s.canUse eq 1">
					<div class="media coupon" userCouponId="{$s.userCouponId}">
						<div class="media">
								
							    <div class="media-left select">
							    	<span></span>
							    </div>
								<div class="media-body  media-middle">
									<h2>{$s.name}</h2>
									<p style="color: #bebcbc;font-size: 12px;">{$s.recommend}</p>
								</div>
								<div class="media-right ">
									<i>¥</i>{$s['money'] | floatval}
								</div>
					    </div>
					    <if condition="$s['isEffective'] eq 1">
						    <p class="ab-bottom">
								{$s.startTime}至{$s.endTime}有效
							</p>
						</if>
					</div>
					</if>
				</volist>
				<else />
				<volist name="couponList" id="c">
					<div class="media coupon disable">
						<div class="media">
							   
								<div class="media-body  media-middle">
									<h2>{$c.name}</h2>
									<p style="color: #bebcbc;font-size: 12px;">{$c.recommend}</p>
								</div>
								<div class="media-right ">
									<i>¥</i>{$c['money'] | floatval}
								</div>
					    </div>
					    <if condition="$c['isEffective'] eq 1">
					    <p class="ab-bottom">
							{$c.startTime}至{$c.endTime}有效
						</p>
						</if>
					</div>
			</volist>
				</if>
			</div>
			<assign name="pre" value="1" />
			<div class="couponBox disablebox">
			<volist name="couponList" id="c">
				
				<if condition="$c.canUse eq 0 and $type eq 0">
				<if condition="$pre eq '1'">
					<div class="title">
						<span class="line"></span>
						<span>以下为不可用优惠券</span>
					</div>
					<assign name="pre" value="2" />
				</if>
					<div class="media coupon disable">
						<div class="media">
							    <div class="media-left select">
							    	<span></span>
							    </div>
								<div class="media-body  media-middle">
									<h2>{$c.name}</h2>
									<p style="color: #bebcbc;font-size: 12px;">{$c.recommend}</p>
								</div>
								<div class="media-right ">
									<i>¥</i>{$c['money'] | floatval}
								</div>
					    </div>
					    <if condition="$c['isEffective'] eq 1">
					    <p class="ab-bottom">
							{$c.startTime}至{$c.endTime}有效
						</p>
						</if>
						<if condition="$type eq '1'">
						<span class="usedTag">
							<img src="{$Think.config.RESOURCEURL}wx_assets/images/product/used.png"/>
						</span>
						</if>
					</div>
				</if>
			</volist>
			</div>
			<div class="usenone">
				<a>本次不使用优惠券</a>
			</div>
		<script>
			$(function(){
				$('.selectList > div').on('click',function(){
					var me=$(this);
					var userCouponId=me.attr('userCouponId');
					if(me.hasClass('active'))
					{
						$('.selectList > div').removeClass('active');
					}
					else
					{
						$('.selectList > div').removeClass('active');
						me.addClass('active');
					}
					updateOrderCoupon(userCouponId);
				});
				$('.usenone').on('click',function(){
					updateOrderCoupon('""');
				})
				
				var updateOrderCoupon=function(userCouponId){
					var oid=$.util.getParamAsObject().oid;
					var ids=$.util.getParamAsObject().ids;
					$.ajax({
						url:'call.json?customerId={$customerId}&module=product&method=updateOrderCoupon&params=%7B%22oid%22:'+oid+',%22userCouponId%22:'+userCouponId+'%7D',
						type:'GET',
						dataType:'JSON',
						beforeSend:function(){
							$.util.pageLoading.show();
						},
						success:function(data){
							$.util.pageLoading.hide();
							if(data.code==0)
							{
								location.href='call.html?customerId={$customerId}&module=product&method=getOrderDetail&params=%7B%22tplid%22:1,%22id%22:%22'+ids+'%22,%22notUse%22:1%7D'
							}
							console.log(data);
						}
					})
				}
				
				wx_share.init({
					        "pkg":{
					            "appId": '{$pkg.appId}',
					            "timestamp": {$pkg.timestamp},
					            "nonceStr": '{$pkg.nonceStr}',
					            "signature": '{$pkg.signature}'
					        },
					        "hideAllnone":true
					       
			    });
			})
		</script>
	</body>
</html>
